// shouye/xiangqing/xiangqing.js
var app=getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id:0,
    userId:'',
    name:'',   
    zongzi:'',
    neirong:'',
    address:'',  
    destxt:'',
    imgsrc1:'', 
    prices:'',  
    deadline:'',
    workadd:'',
    information:'',
    assembleArray:'',
    lessonArray:'', imgsrc:'http://icon.tongchengyouzhi.com/default_img.png',
    display1: "block",
    display2: "none",
    display3: "none",
    display4: "none"
  },
   toNews:function(event){
     var that=this
     wx.navigateTo({
       url: '/xiaoxi/chat/chat?id='+that.data.userId,
     })
   },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    // var that=this
    // var id=1001
    this.setData({
      id:options.id 
    })
   
  },
  callBackFun:function(res){
     console.log(res.data.data)
  },
  selected:function(event)
  { 

    var that=this;
    console.log(event.detail)
    var chioce = event.detail.id
    console.log(that.data.assembleArray)
     switch(chioce)
     {
       case 1:
       
      that.setData({
        display1: "block",
        display2: "none",
        display3: "none",
        display4: "none"
      })
       break;
       
       case 2:
         that.setData({
           display1: "none",
           display2: "block",
           display3: "none",
           display4: "none"
         })
         break;
       case 3:
         that.setData({
           display1: "none",
           display2: "none",
           display3: "block",
           display4: "none"
         })
         break;
       case 4:
         that.setData({
           display1: "none",
           display2: "none",
           display3: "none",
           display4: "block"
         })
         break;
       default:
         that.setData({
           id: 555
         })
        
     }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },
  
 
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that=this
    wx.request({
      url: app.globalData.baseUrl + 'mechanism/id',
      data: {
        id: that.data.id
      },
      method: 'GET',
      header: {
        'cookie': 'JSESSIONID=' + wx.getStorageSync('sessionID')
      },
      success: function (res) {
        console.log(res)
        var resData = res.data.data
        var length = resData.imgList.length
        var random = Math.floor(Math.random() * length)
        try{
          that.setData({
            imgsrc: resData.img,
            name: resData.name,
            userId: resData.user.id,
            zongzi: resData.purpose,
            neirong: resData.businessScope,
            address: resData.position,
            destxt: resData.introduce,
            // imgsrc1: resData.imgList[random].url,
            information:resData.recruitList[0].introduce,
            prices:resData.recruitList[0].salary,
            workadd:resData.recruitList[0].position,
            deadline:resData.recruitList[0].description
            
          })
          try{
            that.setData({
              imgsrc1: resData.imgList[random].url,
            })
           
          }catch(err){

          }
        }catch(err){
          console.log(err)
        }
        try{
          for (var i = 0; i < resData.assembleList.length;i++){
            var id='assembleArray['+i+'].id'
            var name ='assembleArray['+i+'].name'
            var newprice = 'assembleArray[' + i + '].newprice'
            var people = 'assembleArray[' + i + '].people'
            var oldprice = 'assembleArray[' + i + '].oldprice'
            var description = 'assembleArray[' + i + '].description'
            var num = 'assembleArray[' + i + '].num'
            var time = 'assembleArray[' + i + '].time'
            var address = 'assembleArray[' + i + '].address'
            var coverImg='assembleArray['+i+'].coverImg'
            that.setData({
              [id]:resData.assembleList[i].id,
              [name]:resData.assembleList[i].title,
              [newprice]:resData.assembleList[i].priceNow,
              [oldprice]:resData.assembleList[i].priceOld,
              [people]:resData.assembleList[i].studentTotal,
              [num]:resData.assembleList[i].studentCurrent,
              [description]:resData.assembleList[i].introduce,
              [time]: resData.assembleList[i].schoolTimeDescription,
              [coverImg]: resData.assembleList[i].coverImg,
              [address]:resData.assembleList[i].position
            })

          }
        }catch(err){
            console.log(err)
        }
        try {
          for (var i = 0; i < resData.boutiqueList.length; i++) {
            var name = 'lessonArray[' + i + '].name'
            var newprice = 'lessonArray[' + i + '].newprice'
            var people = 'lessonArray[' + i + '].people'
            var oldprice = 'lessonArray[' + i + '].oldprice'
            var description = 'lessonArray[' + i + '].description'
            var num = 'lessonArray[' + i + '].num'
            var time = 'lessonArray[' + i + '].time'
            var address = 'lessonArray[' + i + '].address'
            var coverImg = 'lessonArray[' + i + '].coverImg'
            that.setData({
              [name]: resData.boutiqueList[i].title,
              [newprice]: resData.boutiqueList[i].priceNow,
              [oldprice]: resData.boutiqueList[i].priceOld,
              [people]: resData.boutiqueList[i].studentTotal,
              [description]: resData.boutiqueList[i].introduce,
              [time]: resData.boutiqueList[i].schoolTimeDescription,
              [coverImg]: resData.boutiqueList[i].coverImg,
              [address]: resData.boutiqueList[i].position
            })

          }
        } catch (err) {
          console.log(err)
        }

      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow()
    wx.showToast({
      icon: 'none',
      title: '刷新成功'
    })
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})